const Handlebars = require('handlebars')

/** ---- 注册过滤器 ---- */

// 根据值类型判断是否加''
Handlebars.registerHelper('formatValue', (value) => {
    return typeof value === 'string' ? `'${value}'` : value
})

// 遍历对象
Handlebars.registerHelper('eachObject', (context, options) => {
    let ret = ''
    for (const key in context) {
        if (context.hasOwnProperty(key)) {
            ret += options.fn({ key, value: context[key] })
        }
    }
    return ret
})

module.exports = Handlebars
